﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using IntfClass;


namespace IntfSetting.FrmIntf
{
    public partial class FrmFreStep1 : Form
    {
        public FrmFreStep1(DataRow drRow)
        {
            InitializeComponent();
            this.drRow = drRow;
        }

        private DataRow drRow = null;
        public DataTable dtStartTime = new DataTable();
        public DateTime ExecutionTime;
        private void btnCancle_Click(object sender, EventArgs e)
        {
            this.Hide();
            

            if (radDay.Checked)
            {
                drRow["Kind"] = "1";
                FrmFreStep2 frmFreStep2 = new FrmFreStep2(drRow["ID"].ToString(), drRow["Frequency"].ToString());
                frmFreStep2.drSource = drRow;
                if (frmFreStep2.ShowDialog() == DialogResult.Cancel)
                {
                    this.Show();
                    return;
                }

                ClassDB classDB = new ClassDB();
                DataTable dtNow = classDB.ExecuteDataTable("select getdate() as DBDateTime");
                DateTime dateTime = Convert.ToDateTime(dtNow.Rows[0]["DBDateTime"]);
                drRow["Frequency"] = Convert.ToInt16(frmFreStep2.strFre);
                //if (frmFreStep2.blnTiming)
                //{
                //    drRow["Frequency"] = Convert.ToInt32(frmFreStep2.strFre);
                //    //drRow["blnTiming"] = 1;

                //    ExecutionTime = dateTime.AddMinutes(Convert.ToDouble(frmFreStep2.strFre));

                //}
                //else
                //{
                //    //drRow["blnTiming"] = 0;
                //    this.dtStartTime = frmFreStep2.dtGridView.DefaultView.ToTable();

                //}
                this.dtStartTime = frmFreStep2.dtGridView.DefaultView.ToTable();

                //drRow["ExecutionTime"] = ExecutionTime;

                this.DialogResult = DialogResult.OK;

            }
            else if (radWeek.Checked)
            {
                drRow["Kind"] = "2";
                //drRow["blnTiming"] = 0;

                FrmFreStep4 frmFreStep4 = new FrmFreStep4(drRow["ID"].ToString());
                frmFreStep4.strWeek = drRow["WeekDay"].ToString();
                if (frmFreStep4.ShowDialog() == DialogResult.Cancel)
                {
                    this.Show();
                    return;
                }

                this.dtStartTime = frmFreStep4.dtGridView.DefaultView.ToTable();
                string strWeekDay = string.Empty;
                strWeekDay = frmFreStep4.strWeek;
                //ExecutionTime = intfsetting.CalculateExecutionTime("2", dtStartTime, strWeekDay);

                drRow["WeekDay"] = strWeekDay;
                //drRow["ExecutionTime"] = ExecutionTime;

                this.DialogResult = DialogResult.OK;

            }
            else if (radMonth.Checked)
            {
                drRow["Kind"] = "3";
                //drRow["blnTiming"] = 0;

                FrmFreStep5 frmFreStep5 = new FrmFreStep5(drRow["ID"].ToString());
                frmFreStep5.strMonth = drRow["MonthDay"].ToString();
                if(frmFreStep5.ShowDialog() == DialogResult.Cancel)
                {
                    this.Show();
                    return;
                }

                this.dtStartTime = frmFreStep5.dtGridView.DefaultView.ToTable();
                string strMonthDay = string.Empty;
                strMonthDay = frmFreStep5.strMonth;
                //ExecutionTime = intfsetting.CalculateExecutionTime("3", dtStartTime, strMonthDay);


                drRow["MonthDay"] = strMonthDay;
                //drRow["ExecutionTime"] = ExecutionTime;

                this.DialogResult = DialogResult.OK;

            }
            else if (radYear.Checked)
            {
                drRow["Kind"] = "4";
                //drRow["blnTiming"] = 0;

                FrmFreStep6 frmFreStep6 = new FrmFreStep6(drRow["ID"].ToString());
                if (frmFreStep6.ShowDialog() == DialogResult.Cancel)
                {
                    this.Show();
                    return;
                }

                this.dtStartTime = frmFreStep6.dtGridView.DefaultView.ToTable();

                //ExecutionTime = intfsetting.CalculateExecutionTime("3", dtStartTime, string.Empty);

                //drRow["ExecutionTime"] = ExecutionTime;

                this.DialogResult = DialogResult.OK;

            }

        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void FrmFreStep1_Load(object sender, EventArgs e)
        {
            if (!(drRow == null))
            {
                string strKind = drRow["Kind"].ToString();

                if (strKind.Equals("1"))
                {
                    radDay.Checked = true;
                }
                else if (strKind.Equals("2"))
                {
                    radWeek.Checked = true;
                }
                else if (strKind.Equals("3"))
                {
                    radMonth.Checked = true;
                }
                else if (strKind.Equals("4"))
                {
                    radYear.Checked = true;
                }

            }
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {

        }
    }
}
